@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

:: Run test program
"a.exe" < "in.txt" > "temp_out.txt" 2>&1

:: Prepare comparison files
type "out.txt" | find /v "" > "expected.tmp"
type "temp_out.txt" | find /v "" > "actual.tmp"

:: Initialize counters
set /a total=0
set /a passed=0

:: Line-by-line comparison
for /f "tokens=1* delims=:" %%a in ('findstr /n "^" "expected.tmp"') do (
    set /a total+=1
    set expected=%%b
    set actual=

    for /f "tokens=1* delims=:" %%c in ('findstr /n "^" "actual.tmp" ^| findstr /b "%%a:"') do (
        set actual=%%d
    )

    if "!expected!"=="!actual!" (
        echo   !total! PASS✅
        set /a passed+=1
    ) else (
        echo   !total! FAIL❌
        echo     Actual: !actual!
        echo     Expected: !expected!
        echo.
    )
)

:: Print summary
echo ==== TEST RESULTS ====
echo   Passed: !passed!/!total!
if !passed! equ !total! (
    echo   ALL TESTS PASSED
) else (
    echo   SOME TESTS FAILED
)
echo ==================

:: Cleanup
del "temp_out.txt" 2>nul
del "expected.tmp" 2>nul
del "actual.tmp" 2>nul
